<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0,user-scalable=no,minimal-ui">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../img/asset-favico.ico">
    <title>登录</title>

    <link rel="stylesheet" href="../css/page-health-login.css" />

    <script src="../js/axios-0.18.0.js"></script>
    <script src="../js/vue.js"></script>
</head>

<body data-spy="scroll" data-target="#myNavbar" data-offset="150">
    <div id="app">
        <!-- 页面头部 -->
        <div id="top-header">
            <span class="f-left" onclick="goBack()"><i class="icon-back"></i>返回</span>
            <span class="center">千锋健康</span>
            <span class="f-right"><i class="icon-more"></i></span>
        </div>
        <!-- 页面内容 -->
        <div class="contentBox">
            <div class="login">
                <form id='login-form' class="input-group">
                    <div class="input-row">
                        <label>用户名</label>
                        <input id="account" v-model="user.username" type="text" class="input-clear input" placeholder="请输入用户名">
                    </div>
                    <div class="input-row">
                        <label>密码</label>
                        <input id="password" v-model="user.password" type="password" class="input-clear input" placeholder="请输入密码">
                    </div>
                    <div class="btn yes-btn"><a @click="login()">确认</a></div>
                    <div class="btn cancel-btn">取消</div>
                </form>
            </div>
        </div>
    </div>
    <!-- 页面 css js -->

<script>
    new Vue({
        el:"#app",
        data:{
            user:{
                username:"",
                password:""
            }
        },
        methods:{
            login(){
                axios({
                    url:"http://localhost:8081/login",
                    method:"post",
                    params: this.user
                }).then(resp=>{
                    let r = resp.data;
                    let code = r.code;
                    if (code == 200){
                        localStorage.setItem("security_token",r.message);
                        location.href = "health-index.html"
                    }else{
                        let r = resp.data;
                        alert(r.message)
                        location.href = "health-login.html"
                    }
                })
            }
        }
    })
    function goBack() {
        window.history.back();
    }
</script>
</body>